package com.jay.media.music.soundeffect

import android.media.audiofx.Equalizer
import android.util.Log
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.jay.base.ui.BaseActivity
import com.jay.media.music.route.RouteConfig
import java.util.logging.Logger

@Route(
    path = RouteConfig.SoundEffect.SoundEffect
)
class SoundEffectActivity : BaseActivity() {

    @JvmField
    @Autowired(name = RouteConfig.Param.AudioSessionId)
    var audioSessionId = 0

    private lateinit var equalizer: Equalizer

    override fun layoutId(): Int {
        return R.layout.activity_sound_effect
    }

    override fun initData() {
        Log.d(TAG, "audio session id $audioSessionId")
        equalizer = Equalizer(0, audioSessionId)

        Log.d(TAG, "audio bands ${equalizer.numberOfBands}")
        Log.d(TAG, "audio presets ${equalizer.numberOfPresets}")

        for (i in 0 until equalizer.numberOfBands) {
            val bandLevel = equalizer.getBandLevel(i.toShort())
            Log.d(TAG, "band $i , bandLevel $bandLevel")

            val bandFreqRange = equalizer.getBandFreqRange(i.toShort())
            val centerFreq = equalizer.getCenterFreq(i.toShort())
            Log.d(TAG, "band center freq ${i}, $centerFreq, ${equalizer.getBand(centerFreq)}")
        }


        for (i in 0 until equalizer.numberOfPresets) {
            val presetName = equalizer.getPresetName(i.toShort())
            Log.d(TAG, "present $i, presetName $presetName")
        }

        equalizer.usePreset(1)

        Log.d(TAG, "audio bands ${equalizer.numberOfBands}")
        Log.d(TAG, "audio presets ${equalizer.numberOfPresets}")

        for (i in 0 until equalizer.numberOfBands) {
            val bandLevel = equalizer.getBandLevel(i.toShort())
            Log.d(TAG, "band $i , bandLevel $bandLevel")

            val bandFreqRange = equalizer.getBandFreqRange(i.toShort())
            val centerFreq = equalizer.getCenterFreq(i.toShort())
            Log.d(TAG, "band center freq ${i}, $centerFreq, ${equalizer.getBand(centerFreq)}")
        }

    //        var settings = equalizer.properties
//        val config = Equalizer.Settings(settings.toString())
//        config.curPreset = 6
//        config.bandLevels[0] = 0
//        config.bandLevels[1] = 0
//        config.bandLevels[2] = 0
//        equalizer.properties = config
    }
}